package com.wnnight.wys.web.notice;

import com.wnnight.wys.entity.notice.NoticeType;
import com.wnnight.wys.service.notice.NoticeTypeService;
import com.wnnight.wys.vo.NoticeTypeVo;
import com.wnnight.wys.vo.ResultVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName: NoticeTypeController
 * @Description: //TODO
 * @author: xjh
 * @date: 2022/8/31-10:54
 * @version: v1.0
 */
@Slf4j
@RestController
@RequestMapping("/api/v1/notice/noticeType")
public class NoticeTypeController {
    @Autowired
    private NoticeTypeService noticeTypeService;

    //等会数据库加一下这个权限

    @PostMapping("/list")
    public ResultVo<List<NoticeType>> getAll(){
        return new ResultVo<>(noticeTypeService.list());
    }

    @PreAuthorize("hasAuthority('notice:noticeType:add')")
    @PostMapping("/add")
    public ResultVo<?> add(@RequestBody NoticeTypeVo noticeTypeVo){
        System.out.println(noticeTypeVo.getType());
        String type=noticeTypeVo.getType();
        if(type!=null||type.equals("")){
            NoticeType noticeType=new NoticeType();
            noticeType.setType(type);
            noticeTypeService.save(noticeType);
            return ResultVo.SUCCESS;
        }else{
            return ResultVo.FAIL;
        }
    }
}
